package com.icoolkj.ms.user.controller;

import com.icoolkj.ms.api.auth.bo.UserInfoInTokenBO;
import com.icoolkj.ms.api.user.vo.UserApiVO;
import com.icoolkj.ms.common.core.enums.ResponseEnum;
import com.icoolkj.ms.common.core.response.MapBean;
import com.icoolkj.ms.common.core.response.ServerResponseEntity;
import com.icoolkj.ms.common.security.AuthUserContext;
import com.icoolkj.ms.user.service.IUserService;
import com.icoolkj.ms.user.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author icoolkj
 * @version 1.0
 * @description 用户信息业务处理
 * @createDate 2025/03/04 21:28
 */
@RestController
@RequestMapping("/user/profile")
public class UserProfileController {

    @Autowired
    private IUserService iUserService;

    @GetMapping
    public ServerResponseEntity<MapBean> profile() {
        MapBean mapBean = MapBean.create();
        UserInfoInTokenBO userInfoInTokenBO = AuthUserContext.get();
        if (userInfoInTokenBO == null) {
            return ServerResponseEntity.fail(ResponseEnum.TOKEN_EXPIRE);
        }
        UserApiVO userApiVO = iUserService.getUserInfoByUserId(userInfoInTokenBO.getUserId());
        if (userApiVO == null) {
            return ServerResponseEntity.fail(ResponseEnum.USER_NOT_FOUND);
        }
        mapBean.withParameter("user", userApiVO);
        mapBean.withParameter("roleGroup", "角色组");
        mapBean.withParameter("postGroup", "岗位组");
        return ServerResponseEntity.success(mapBean);
    }


}
